package com.qingcheng.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.order.Order;
import com.qingcheng.pojo.order.OrderAndOrderItem;
import com.qingcheng.service.order.OrderService;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    @GetMapping("/findAll")
    public List<Order> findAll(){
        return orderService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Order> findPage(int page, int size){
        return orderService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String,Object> searchMap){
        return orderService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  orderService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Order findById(String id){
        return orderService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Order order){
        orderService.add(order);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Order order){
        orderService.update(order);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(String id){
        orderService.delete(id);
        return new Result();
    }
    // 查询 订单 详情 --> 需要组合实体类   OderAndOrderItem  order 和 orderItem
@RequestMapping("/findOrderDetails")
    public OrderAndOrderItem findOrderDetails(String orderId){
    return orderService.findOrderDetails(orderId);
}

    /**
     * 查询未发货
     * @param ids
     * @return
     */
    @GetMapping("/queryOrderStatus")
    public List<Order> queryOrderStatus(String[] ids) {
        return orderService.queryOrderStatus(ids);
    }

    /**
     * 批量发货
     * @param orderList
     * @return
     */
    @PostMapping("updateOrderStatus")
    public Result updateOrderStatus(@RequestBody  List<Order> orderList) {

        orderService.updateOrderStatus(orderList);
        return new Result();
    }

    /**
     *合并订单
     * @param orderId1
     * @param orderId2
     * @return
     */
    @GetMapping("mergeOrder")
    public Result mergeOrder(String orderId1 ,String orderId2){
        orderService.mergeOrder(orderId1,orderId2);
        return new Result();
    }
}
